package com.springboot.codeminestarter.codemine.business.log.controller;

import com.springboot.codeminestarter.codemine.business.log.domain.LogRecord;
import com.springboot.codeminestarter.codemine.domain.ResponseWrapper;
import com.springboot.codeminestarter.codemine.aop.log.LogWrite;
import com.springboot.codeminestarter.codemine.business.log.service.LogWrapperService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Tag(name = "日志模块")
@RestController
@RequestMapping("/log")
public class LogWrapperController {

    private static final Logger LOGGER = LoggerFactory.getLogger(LogWrapperController.class);

    @Resource
    private LogWrapperService logWrapperService;

    @Operation(summary = "根据ID查询日志")
    @Parameter(in = ParameterIn.QUERY, name = "id", required = true, description = "日志主键")
    @ApiResponse(responseCode = "10000", description = "根据ID查询日志成功")
    @LogWrite("根据ID查询日志")
    @GetMapping(value = "/wrapper")
    public ResponseWrapper getLogWrapper(@RequestParam(value = "id") String id) {

        return ResponseWrapper.Success(logWrapperService.getLogWrapperService(id));
    }

    @Operation(summary = "根据ID查询日志")
    @Parameter(in = ParameterIn.QUERY, name = "id", required = true, description = "日志主键")
    @ApiResponse(responseCode = "10000", description = "根据ID查询日志成功")
    @LogWrite("根据ID查询日志")
    @GetMapping(value = "/wrapper2")
    public ResponseWrapper getLogWrapper2(@RequestParam(value = "id") String id) {

        return ResponseWrapper.Success(logWrapperService.getLogWrapper2Service(id));
    }

    @Operation(summary = "根据ID查询日志")
    @Parameter(in = ParameterIn.QUERY, name = "id", required = true, description = "日志主键")
    @ApiResponse(responseCode = "10000", description = "根据ID查询日志成功")
    @LogWrite("根据ID查询日志")
    @GetMapping(value = "/wrapper3")
    public ResponseWrapper getLogWrapper3(@RequestParam(value = "id") String id) {

        return ResponseWrapper.Success(logWrapperService.getLogWrapper3Service(id));
    }

    @Operation(summary = "新增单条日志")
    @ApiResponse(responseCode = "10000", description = "新增日志成功")
    @LogWrite("新增接口日志")
    @PostMapping(value = "/add/logWrapper")
    public ResponseWrapper addLogWrapper(@RequestBody LogRecord record) {

        logWrapperService.addLogWrapper(record);
        return ResponseWrapper.Success();
    }
}
